package cn.vc.auth.handler;

import cn.messageplus.core.annotation.MessagePlusHandler;
import cn.messageplus.core.util.MpcUtil;
import cn.vc.auth.message.request.ShareRequest;
import cn.vc.auth.message.response.ShareResponse;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * 分享请求处理器
 */
@Slf4j
@MessagePlusHandler
@ChannelHandler.Sharable
public class ShareRequestHandler extends SimpleChannelInboundHandler<ShareRequest> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, ShareRequest shareRequest) throws Exception {
        // 1.创建响应对象
        ShareResponse shareResponse = new ShareResponse();
        // 2.拷贝
        BeanUtils.copyProperties(shareRequest, shareResponse);
        shareResponse.setTitle(shareRequest.getTitle());
        shareResponse.setCoverUrl(shareRequest.getCoverUrl());
        shareResponse.setUrl(shareRequest.getUrl());
        // 3.响应请求
        MpcUtil.send(shareResponse);
    }
}
